<!-- 个人中心 -->
<template>
  <view class="personal-wrap">
    <!-- 个人信息卡片 -->
    <userinfo-card ref="card" :scrollTop="scrollTop" :detail="userHeadData" :num="num"></userinfo-card>
    <!-- 订单卡片 -->
    <sh-order-card></sh-order-card>
    <!-- 九宫格列表 -->
    <sh-grid v-if="list.length>0" :list="list" @onShare="onShare"></sh-grid>
    <!-- #ifdef H5 -->
    <view class="tabbar-hack" style="height: 120rpx; width:100%;"></view>
    <!-- #endif -->
    <!-- 登录提示 -->
    <shopro-auth-modal v-if="authType"></shopro-auth-modal>
    <!-- 分享组件 -->
    <shopro-share v-model="showShare" :shareDetail="shareInfo" posterType="user"></shopro-share>
    <!-- <button @click="share()">分享</button> -->
  </view>
</template>

<script>
  import shBanner from './components/sh-banner.vue';
  import shGridSwiper from './components/sh-grid-swiper.vue';
  import shHotGoods from './components/sh-hot-goods.vue';
  import shAdv from './components/sh-adv.vue';
  import shCoupon from './components/sh-coupon.vue';
  import shSeckill from './components/sh-seckill.vue';
  import shGroupon from './components/sh-groupon.vue';
  import shRichtext from './components/sh-richtext.vue';
  import shCell from './components/sh-cell.vue';
  import shGrid from './components/sh-grid.vue';
  import shTitleCard from './components/sh-title-card.vue';
  import shOrderCard from './components/sh-order-card.vue';
  import shWallet from './components/sh-wallet.vue';
  import shSearch from './components/sh-search.vue';
  import shCategoryTabs from './components/sh-category-tabs.vue';

  import userinfoCard from './user/userinfo-card.vue';

  import {
    mapMutations,
    mapActions,
    mapState
  } from 'vuex';

  // #ifdef MP-WEIXIN
  import {
    HAS_LIVE
  } from '@/env';
  import shLive from './components/sh-live.vue';
  // #endif

  import share from '@/shopro/share';

  export default {
    components: {
      shBanner,
      shGridSwiper,
      shGroupon,
      shHotGoods,
      shAdv,
      shCoupon,
      shSeckill,
      shRichtext,
      shCell,
      shGrid,
      shTitleCard,
      shWallet,
      shOrderCard,
      shSearch,
      shCategoryTabs,
      userinfoCard,
      // #ifdef MP-WEIXIN
      shLive
      // #endif
    },
    data() {
      return {
        // #ifdef MP-WEIXIN
        HAS_LIVE: HAS_LIVE,
        // #endif
        scrollTop: 0,
        num: {
          today_group: 0,
          today_win: 0
        },
        list: [{
            path: "/pages/user/wallet/index", //跳转路径
            name: "钱包", //菜单名字
            image: "../../static/images/newUser/wallet.png" //菜单图片
          }, {
            path: "/pages/user/wallet/score-balance", //跳转路径
            name: "积分", //菜单名字
            image: "../../static/images/newUser/score.png" //菜单图片
          }, {
            path: "/pages/user/wallet/withdraw", //跳转路径
            name: "提现", //菜单名字
            image: "../../static/images/newUser/cash.png" //菜单图片
          }, {
            path: "/pages/activity/groupon/my-groupon", //跳转路径
            name: "我的拼购", //菜单名字
            image: "../../static/images/newUser/groupon.png" //菜单图片
          },
          {
            path: "/pages/user/real", //跳转路径
            name: "实名认证", //菜单名字
            image: "../../static/images/newUser/real.png" //菜单图片
          },
          {
            path: "/pages/user/favorite", //跳转路径
            name: "收藏商品", //菜单名字
            image: "../../static/images/newUser/favorite.png" //菜单图片
          }, {
            path: "/pages/public/invite", //跳转路径
            name: "邀请好友", //菜单名字
            image: "../../static/images/newUser/invite.png" //菜单图片
          }, {
            path: "/pages/app/team/index", //跳转路径
            name: "我的好友", //菜单名字
            image: "../../static/images/newUser/team.png" //菜单图片
          }, {
            path: "/pages/user/address/list", //跳转路径
            name: "收货地址", //菜单名字
            image: "../../static/images/newUser/address.png" //菜单图片
          }, {
            path: "/pages/public/faq", //跳转路径
            name: "帮助中心", //菜单名字
            image: "../../static/images/newUser/help.png" //菜单图片
          }, {
            path: "/pages/user/set", //跳转路径
            name: "设置", //菜单名字
            image: "../../static/images/newUser/set.png" //菜单图片
          },
        ], //菜单列表
        showShare: false,
        enable: false //是否开启吸顶。
      };
    },
    computed: {
      ...mapState({
        shop: ({
          shopro
        }) => shopro.config?.shop, // 版本信息
        userTemplate: ({
          shopro
        }) => shopro.template?.user, //模板数据
        userInfo: ({
          user
        }) => user.userInfo,
        isLogin: ({
          user
        }) => user.isLogin,
        authType: ({
          user
        }) => user.authType
      }),
      userHeadData() {
        if (this.userTemplate?.length) {
          return this.userTemplate[0].content;
        }
      },
      //分类选项卡数据
      categoryTabsData() {
        if (this.userTemplate?.length) {
          return this.userTemplate[this.userTemplate.length - 1].content;
        }
      }
    },
    // 下拉刷新
    onPullDownRefresh() {
      this.init();
    },
    onPageScroll(e) {
      this.scrollTop = e.scrollTop;
    },

    onShow() {
      // if (this.isLogin) {
      // 	this.init();
      // 	this.getUserData();
      // }
      this.enable = true;
      this.$store.commit('CART_NUM');
      this.setnum();
    },

    methods: {
      ...mapActions(['getUserInfo', 'showAuthModal', 'getUserData']),
      onShare() {
        this.shareInfo = share.setShareInfo();
        this.showShare = true;
      },
      setnum() {
        console.log(uni.getStorageSync('token'))
        if (uni.getStorageSync('token') != '') {
          this.$http('user.center').then(res => {
            console.log(res, '拼购次数')
            this.num = res.data;
          })
        }
      },
      // 初始化
      init() {
        this.getUserInfo()
          .then(res => {
            uni.stopPullDownRefresh();
          })
          .catch(e => {
            uni.stopPullDownRefresh();
          });
      },
      share() {
        uni.share({
          provider: "weixin",
          scene: "WXSceneSession",
          type: 1,
          summary: "我正在使用HBuilderX开发uni-app，赶紧跟我一起来体验！",
          success: function(res) {
            console.log("success:" + JSON.stringify(res));
          },
          fail: function(err) {
            console.log("fail:" + JSON.stringify(err));
          }
        });
      }
    }
  };
</script>

<style lang="scss">
  .copyright-box {
    .copyright-text {
      font-size: 22rpx;
      font-weight: 500;
      color: #c4c4c4;
    }
  }
</style>
